package com.koocloud.electroplatemanage.service.impl;

import cn.hutool.core.lang.Validator;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koocloud.electroplatemanage.auth.mapper.IUserDao;
import com.koocloud.electroplatemanage.common.pojo.ResponseTemplate;
import com.koocloud.electroplatemanage.mapper.MainProductionMapper;
import com.koocloud.electroplatemanage.pojo.Process;
import com.koocloud.electroplatemanage.pojo.User;
import com.koocloud.electroplatemanage.pojo.mainpojo.*;
import com.koocloud.electroplatemanage.service.MainProductionService;
import com.koocloud.electroplatemanage.utils.HexUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.LinkedHashMap;
import java.util.List;

import static com.koocloud.electroplatemanage.constant.IncomePartJudgeSqlFieldConstant.ONE;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import static com.koocloud.electroplatemanage.constant.MainWIPRouteConstant.PROCESSPREPARATION;

/**
 * @program: electroplatemanage
 * @description: 主要生产活动服务实现类
 * @author: zww
 * @create: 2020-11-16 11:56
 */
@Service
@Transactional(rollbackFor=Exception.class)
public class MainProductionServiceImpl implements MainProductionService {
    @Resource
    MainProductionMapper mainProductionMapper;
    @Resource
    IUserDao iUserDao;
    Lock lock=new ReentrantLock();
    /**
     *@Description:通过pk查询生产计划实绩表
     *@Param: []
     *@return: com.koocloud.electroplatemanage.pojo.mainpojo.OrderResource
     *@Author: zww
     *@date: 2020/11/16
     */
    @Override
    public OrderResource selectOrderResourceByPk(int id) {
        OrderResource orderResource = null;
        try {
            //生产实绩查询
            orderResource = mainProductionMapper.selectOrderResourceByPk(id);
            //判断查表操作是否成功
            if (null != orderResource) {
                orderResource.setCode("0");
                orderResource.setMessage("查询成功");
                //查表成功返回数据
                return orderResource;
            }
            else {
                orderResource.setCode("1");
                orderResource.setMessage("没有查到数据");
                //查表失败返回提示
                return orderResource;
            }
        } catch (Exception e) {
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //遇到异常，返回异常原因
            e.printStackTrace();
            orderResource.setCode("1");
            orderResource.setMessage(e.getMessage());
            return orderResource;
        }

    }
    /**
     *@Description:新增生产计划实绩表
     *@Param: [orderResource]
     *@return: int
     *@Author: zww
     *@date: 2020/11/16
     */
    @Override
    public OrderResource insertOrderResource(OrderResource orderResource) {
        try {
            lock.lock();
            //生产实绩插入
            int rows = mainProductionMapper.insertOrderResource(orderResource);
            //判断新增操作是否成功
            if (rows > 0) {
                orderResource.setCode("0");
                orderResource.setMessage("插入成功");
                //插入成功返回数据
                return orderResource;
            }
            else {
                orderResource.setCode("1");
                orderResource.setMessage("插入失败");
                //插入失败返回提示
                return orderResource;
            }
        } catch (Exception e) {
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //遇到异常，返回异常原因
            e.printStackTrace();
            orderResource.setCode("1");
            orderResource.setMessage(e.getMessage());
            return orderResource;
        }
        finally {
            lock.unlock();
        }
    }
    /**
     *@Description:修改生产计划实绩表
     *@Param: [orderResource]
     *@return: int
     *@Author: zww
     *@date: 2020/11/16
     */
    @Override
    public OrderResource updateOrderResource(OrderResource orderResource) {
        try {
            lock.lock();
            //生产实绩修改
            int rows = mainProductionMapper.updateOrderResource(orderResource);
            //判断修改操作是否成功
            if (rows > 0) {
                orderResource.setCode("0");
                orderResource.setMessage("修改成功");
                //修改成功返回数据
                return orderResource;
            }
            else {
                orderResource.setCode("1");
                orderResource.setMessage("修改失败");
                //修改失败返回提示
                return orderResource;
            }
        } catch (Exception e) {
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //遇到异常，返回异常原因
            e.printStackTrace();
            orderResource.setCode("1");
            orderResource.setMessage(e.getMessage());
            return orderResource;
        }
        finally {
            lock.unlock();
        }
    }


    /**
     *@Description: 查询所有生产实绩表数据
     *@Param: [page, limit, beginTime, endTime, idOrName]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/21
     */
    @Override
    public ResponseTemplate selectOrderResourceAllData(String page, String limit, String beginTime, String endTime, String idOrName) {
        //校验分页参数是否为纯数字 并且page和limit不都等于0
        if (Validator.isNumber(page) && Validator.isNumber(limit) && !("0".equals(page) && "0".equals(limit))) {
            try {
                String startTime = null;
                String finishTime = null;
                Calendar cal = Calendar.getInstance();
                //取当年年份
                String year = String.valueOf(cal.get(Calendar.YEAR));
                String month = String.valueOf(cal.get(Calendar.MONTH)+1);
                if (ONE.equals(month)){
                    startTime = (Integer.parseInt(year)-1)+"-12-25";
                    finishTime = year+"-" +String.format("%02d",month)+"-26";
                }else {
                    startTime = year+"-" +String.format("%02d",(Integer.parseInt(month)-1))+"-25";
                    finishTime = year+"-" +String.format("%02d",Integer.parseInt(month))+"-26";
                }
                if (StringUtils.isEmpty(beginTime)){
                    beginTime= startTime;
                }
                if (StringUtils.isEmpty(endTime)){
                    endTime= finishTime;
                }
                PageHelper.startPage(Integer.valueOf(page), Integer.valueOf(limit));
                List<OrderResource> orderResourceList = mainProductionMapper.selectOrderResourceAllData(beginTime,endTime,idOrName);
                PageInfo<OrderResource> info = new PageInfo<>(orderResourceList);
                if (info.getTotal() > 0) {
                    //查询到数据
                    return ResponseTemplate.builder().code(0).message("查询成功").count((long) info.getTotal()).data(info).build();
                } else {
                    //没有查询到数据
                    return ResponseTemplate.builder().code(1).message("没有查到对应数据").count((long) info.getTotal()).data(info).build();
                }
            } catch (Exception e) {
                //事务手动回滚
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                //遇到异常，返回异常原因
                e.printStackTrace();
                return ResponseTemplate.builder().code(1).message(e.getMessage()).count(0l).build();
            }

        } else {
            return ResponseTemplate.builder().code(1).message("分页参数错误").count(0l).build();
        }

    }


    /**
     *@Description:通过pk查询工单拆分表
     *@Param: []
     *@return: com.koocloud.electroplatemanage.pojo.mainpojo.OrderSplit
     *@Author: zww
     *@date: 2020/11/16
     */
    @Override
    public OrderSplit selectOrderSplitByPk(int id) {
        OrderSplit orderSplit = null;
        try {
            //工单拆分查询
            orderSplit = mainProductionMapper.selectOrderSplitByPk(id);
            //判断查表操作是否成功
            if (null != orderSplit) {
                orderSplit.setCode("0");
                orderSplit.setMessage("查询成功");
                //查表成功返回数据
                return orderSplit;
            }
            else {
                orderSplit.setCode("1");
                orderSplit.setMessage("没有查到数据");
                //查表失败返回提示
                return orderSplit;
            }
        } catch (Exception e) {
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //遇到异常，返回异常原因
            e.printStackTrace();
            orderSplit.setCode("1");
            orderSplit.setMessage(e.getMessage());
            return orderSplit;
        }
    }
    /**
     *@Description:新增工单拆分表
     *@Param: [orderSplit]
     *@return: int
     *@Author: zww
     *@date: 2020/11/16
     */
    @Override
    public OrderSplit insertOrderSplit(OrderSplit orderSplit) {
        try {
            lock.lock();
            //工单拆分插入
            int rows = mainProductionMapper.insertOrderSplit(orderSplit);
            //判断新增操作是否成功
            if (rows > 0) {
                orderSplit.setCode("0");
                orderSplit.setMessage("插入成功");
                //插入成功返回数据
                return orderSplit;
            }
            else {
                orderSplit.setCode("1");
                orderSplit.setMessage("插入失败");
                //插入失败返回提示
                return orderSplit;
            }
        } catch (Exception e) {
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //遇到异常，返回异常原因
            e.printStackTrace();
            orderSplit.setCode("1");
            orderSplit.setMessage(e.getMessage());
            return orderSplit;
        }
        finally {
            lock.unlock();
        }
    }
    /**
     *@Description:修改工单拆分表
     *@Param: [orderSplit]
     *@return: int
     *@Author: zww
     *@date: 2020/11/16
     */
    @Override
    public OrderSplit updateOrderSplit(OrderSplit orderSplit) {
        try {
            lock.lock();
            //工单拆分修改
            int rows = mainProductionMapper.updateOrderSplit(orderSplit);
            //判断修改操作是否成功
            if (rows > 0) {
                orderSplit.setCode("0");
                orderSplit.setMessage("修改成功");
                //修改成功返回数据
                return orderSplit;
            }
            else {
                orderSplit.setCode("1");
                orderSplit.setMessage("修改失败");
                //修改失败返回提示
                return orderSplit;
            }
        } catch (Exception e) {
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //遇到异常，返回异常原因
            e.printStackTrace();
            orderSplit.setCode("1");
            orderSplit.setMessage(e.getMessage());
            return orderSplit;
        }
        finally {
            lock.unlock();
        }
    }







    /**
     *@Description:通过pk查询路径表
     *@Param: [id]
     *@return: com.koocloud.electroplatemanage.pojo.mainpojo.Route
     *@Author: zww
     *@date: 2020/11/16
     */
    @Override
    public Route selectRouteByPk(int id) {
        Route route = null;
        try {
            //路径查询
            route = mainProductionMapper.selectRouteByPk(id);
            //判断查表操作是否成功
            if (null != route) {
                route.setCode("0");
                route.setMessage("查询成功");
                //查表成功返回数据
                return route;
            }
            else {
                route.setCode("1");
                route.setMessage("没有查到数据");
                //查表失败返回提示
                return route;
            }
        } catch (Exception e) {
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //遇到异常，返回异常原因
            e.printStackTrace();
            route.setCode("1");
            route.setMessage(e.getMessage());
            return route;
        }
    }
    /**
     *@Description:新增生产路径表
     *@Param: [route]
     *@return: int
     *@Author: zww
     *@date: 2020/11/16
     */
    @Override
    public Route insertRoute(Route route) {

        try {
            lock.lock();
            //路径插入
            int rows = mainProductionMapper.insertRoute(route);
            //判断新增操作是否成功
            if (rows > 0) {
                route.setCode("0");
                route.setMessage("插入成功");
                //插入成功返回数据
                return route;
            }
            else {
                route.setCode("1");
                route.setMessage("插入失败");
                //插入失败返回提示
                return route;
            }
        } catch (Exception e) {
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //遇到异常，返回异常原因
            e.printStackTrace();
            route.setCode("1");
            route.setMessage(e.getMessage());
            return route;
        }
        finally {
            lock.unlock();
        }
    }
    /**
     *@Description:修改生产路径表
     *@Param: [route]
     *@return: int
     *@Author: zww
     *@date: 2020/11/16
     */
    @Override
    public Route updateRoute(Route route) {
        try {
            lock.lock();
            //路径修改
            int rows = mainProductionMapper.updateRoute(route);
            //判断修改操作是否成功
            if (rows > 0) {
                route.setCode("0");
                route.setMessage("修改成功");
                //修改成功返回数据
                return route;
            }
            else {
                route.setCode("1");
                route.setMessage("修改失败");
                //修改失败返回提示
                return route;
            }
        } catch (Exception e) {
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //遇到异常，返回异常原因
            e.printStackTrace();
            route.setCode("1");
            route.setMessage(e.getMessage());
            return route;
        }
        finally {
            lock.unlock();
        }
    }







    /**
     *@Description:通过pk查询生产在工表
     *@Param: [workOrderNumber]
     *@return: com.koocloud.electroplatemanage.pojo.mainpojo.WIP
     *@Author: zww
     *@date: 2020/11/16
     */
    @Override
    public WIP selectWIPByPk(String workOrderNumber) {
        WIP wip = null;
        try {
            //在工查询
            wip = mainProductionMapper.selectWIPByPk(workOrderNumber);
            //判断查表操作是否成功
            if (null != wip) {
                wip.setCode("0");
                wip.setMessage("查询成功");
                //查表成功返回数据
                return wip;
            }
            else {
                wip.setCode("1");
                wip.setMessage("没有查到数据");
                //查表失败返回提示
                return wip;
            }
        } catch (Exception e) {
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //遇到异常，返回异常原因
            e.printStackTrace();
            wip.setCode("1");
            wip.setMessage(e.getMessage());
            return wip;
        }
    }
    /**
     *@Description:分页查询所有数据
     *@Param: [page, limit, beginTime, endTime, wip]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: zww
     *@date: 2020/11/21
     */
    @Override
    public ResponseTemplate selectWIPAllData(String page, String limit, String beginTime, String endTime, WIP wip) {
        //校验分页参数是否为纯数字 并且page和limit不都等于0
        if(Validator.isNumber(page)&&Validator.isNumber(limit)&&!("0".equals(page)&&"0".equals(limit))) {
            try {

                    //开始分页
                    PageHelper.startPage(Integer.valueOf(page), Integer.valueOf(limit));
                    //全局查询
                    List<WIP> ProcessList = mainProductionMapper.selectWIPAllData(wip);
                for (int i = 0; i < ProcessList.size(); i++) {
                    String s = mainProductionMapper.selectRouteById(ProcessList.get(i).getCurrentLocation());
                    ProcessList.get(i).setCurrentLocation(s);
                }

                //构造分页实体
                    PageInfo<WIP> info=new PageInfo<>(ProcessList);
                    if (info.getTotal()>0) {
                        //查询到数据
                        return ResponseTemplate.builder().code(0).message("查询成功").count(info.getTotal()).data(info.getList()).build();
                    } else {
                        //没有查询到数据
                        return ResponseTemplate.builder().code(1).message("没有查到对应数据").count(0l).build();
                    }

            } catch (Exception e) {
                //遇到异常，返回异常原因
                e.printStackTrace();
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return ResponseTemplate.builder().code(1).message(e.getMessage()).count(0l).build();
            }
        } else {
            return ResponseTemplate.builder().code(1).message("分页参数错误").count(0l).build();
        }
    }

    /**
     *@Description:新增生产在工表
     *@Param: [wip]
     *@return: int
     *@Author: zww
     *@date: 2020/11/16
     */
    @Override
    public WIP insertWIP(WIP wip) {

        try {
            lock.lock();
            //在工插入
            int rows = mainProductionMapper.insertWIP(wip);
            //判断新增操作是否成功
            if (rows > 0) {
                wip.setCode("0");
                wip.setMessage("插入成功");
                //插入成功返回数据
                return wip;
            }
            else {
                wip.setCode("1");
                wip.setMessage("插入失败");
                //插入失败返回提示
                return wip;
            }
        } catch (Exception e) {
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //遇到异常，返回异常原因
            e.printStackTrace();
            wip.setCode("1");
            wip.setMessage(e.getMessage());
            return wip;
        }
        finally {
            lock.unlock();
        }
    }
    /**
     *@Description:修改生产在工表
     *@Param: [wip]
     *@return: int
     *@Author: zww
     *@date: 2020/11/16
     */
    @Override
    public WIP updateWIP(WIP wip) {
        try {
            lock.lock();
            //在工修改
            int rows = mainProductionMapper.updateWIP(wip);
            //判断修改操作是否成功
            if (rows > 0) {
                wip.setCode("0");
                wip.setMessage("修改成功");
                //修改成功返回数据
                return wip;
            }
            else {
                wip.setCode("1");
                wip.setMessage("修改失败");
                //修改失败返回提示
                return wip;
            }
        } catch (Exception e) {
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //遇到异常，返回异常原因
            e.printStackTrace();
            wip.setCode("1");
            wip.setMessage(e.getMessage());
            return wip;
        }
        finally {
            lock.unlock();
        }
    }
    /**
     *@Description:删除生产在工表
     *@Param: [workOrderNumber]
     *@return: int
     *@Author: zww
     *@date: 2020/11/16
     */
    @Override
    public WIP deleteWIP(String workOrderNumber) {
        WIP wip = null;
        try {
            lock.lock();
            //在工删除
            int rows = mainProductionMapper.deleteWIP(workOrderNumber);
            //判断修改操作是否成功
            if (rows > 0) {
                wip.setCode("0");
                wip.setMessage("删除成功");
                //修改成功返回数据
                return wip;
            }
            else {
                wip.setCode("1");
                wip.setMessage("删除失败");
                //修改失败返回提示
                return wip;
            }
        } catch (Exception e) {
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //遇到异常，返回异常原因
            e.printStackTrace();
            wip.setCode("1");
            wip.setMessage(e.getMessage());
            return wip;
        }
        finally {
            lock.unlock();
        }
    }
    /**
     *@Description:生产在工流程位置修改
     *@Param: [userId, location]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: zww
     *@date: 2020/11/17
     */
    @Override
    public ResponseTemplate updateLocation(String userId, String location) {
        try {
            lock.lock();
            //设置完成人
            User user = iUserDao.selectByPk(userId);
            if(!StringUtils.isEmpty(user)&&!StringUtils.isEmpty(user.getJobNum())) {
                String userJobNum = user.getJobNum();
            }
            //生产在工流程位置修改
            int rows = mainProductionMapper.updateLocation(userId,location);
            //判断修改操作是否成功
            if (rows > 0) {
                //修改成功返回数据
                return ResponseTemplate.builder().code(0).message("生产在工流程位置修改成功").count(1l).build();
            }
            else {
                //修改失败
                return ResponseTemplate.builder().code(1).message("生产在工流程位置修改失败").count(1l).build();
            }
        } catch (Exception e) {
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //遇到异常，返回异常原因
            e.printStackTrace();
            return ResponseTemplate.builder().code(1).message(e.getMessage()).count(1l).build();
        }
        finally {
            lock.unlock();
        }
    }

    @Override
    public ResponseTemplate selectRouteById(String routeId) {
        try {
            //设置完成人

            //生产在工流程位置修改
            String route = mainProductionMapper.selectRouteById(routeId);
            //判断修改操作是否成功
            if (!StringUtils.isEmpty(route)) {
                //修改成功返回数据
                return ResponseTemplate.builder().code(0).message("路由查找成功").count(1l).data(route).build();
            }
            else {
                //修改失败
                return ResponseTemplate.builder().code(1).message("路由查找失败").count(1l).build();
            }
        } catch (Exception e) {
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //遇到异常，返回异常原因
            e.printStackTrace();
            return ResponseTemplate.builder().code(1).message(e.getMessage()).count(1l).build();
        }
    }
    /**
     *@Description:通过工单号查询生产实绩表列表数据
     *@Param: [workOrderNumber]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: zww
     *@date: 2020/11/24
     */
    @Override
    public ResponseTemplate selectOrderResourceListByWON(String workOrderNumber) {

        try {
            //生产实绩查询
            List<OrderResource> orderResourceList = mainProductionMapper.selectOrderResourceListByWON(workOrderNumber);
            //判断查表操作是否成功
            if (null != orderResourceList) {
                return ResponseTemplate.builder().code(0).message("查询成功").data(orderResourceList).count(0l).build();
            }
            else {
                return ResponseTemplate.builder().code(1).message("暂无数据").count(0l).build();
            }
        } catch (Exception e) {
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //遇到异常，返回异常原因
            e.printStackTrace();
            return ResponseTemplate.builder().code(1).message(e.getMessage()).count(0l).build();
        }
    }

    @Override
    public ResponseTemplate selectWIPByWON(String workOrderNumber) {
        try {
            //生产实绩查询
            WIP wip = mainProductionMapper.selectWIPByPk(workOrderNumber);
            String s = mainProductionMapper.selectRouteById(wip.getCurrentLocation());
            wip.setCurrentLocation(s);
            //判断查表操作是否成功
            if (null != wip) {
                return ResponseTemplate.builder().code(0).message("查询成功").data(wip).count(0l).build();
            }
            else {
                return ResponseTemplate.builder().code(1).message("暂无数据").count(0l).build();
            }
        } catch (Exception e) {
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //遇到异常，返回异常原因
            e.printStackTrace();
            return ResponseTemplate.builder().code(1).message(e.getMessage()).count(0l).build();
        }
    }


    /**
     *@Description:通过pk查询生产工单号表
     *@Param: [workOrderNumber]
     *@return: com.koocloud.electroplatemanage.pojo.mainpojo.WIP
     *@Author: zww
     *@date: 2020/11/16
     */
    @Override
    public WorkOrder selectWorkOrderByPk(String workOrderNumber) {

        WorkOrder workOrder = null;
        try {
            //生产工单号表查询
            workOrder = mainProductionMapper.selectWorkOrderByPk(workOrderNumber);
            //判断查表操作是否成功
            if (null != workOrder) {
                workOrder.setCode("0");
                workOrder.setMessage("查询成功");
                //查表成功返回数据
                return workOrder;
            }
            else {
                workOrder.setCode("1");
                workOrder.setMessage("没有查到数据");
                //查表失败返回提示
                return workOrder;
            }
        } catch (Exception e) {
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //遇到异常，返回异常原因
            e.printStackTrace();
            workOrder.setCode("1");
            workOrder.setMessage(e.getMessage());
            return workOrder;
        }
    }
    /**
     *@Description:新增生产工单号表
     *@Param: [workOrder]
     *@return: int
     *@Author: zww
     *@date: 2020/11/16
     */
    @Override
    public WorkOrder insertWorkOrder(WorkOrder workOrder) {
        try {
            lock.lock();
            //生产工单号插入
            int rows = mainProductionMapper.insertWorkOrder(workOrder);
            //判断新增操作是否成功
            if (rows > 0) {
                workOrder.setCode("0");
                workOrder.setMessage("插入成功");
                //插入成功返回数据
                return workOrder;
            }
            else {
                workOrder.setCode("1");
                workOrder.setMessage("插入失败");
                //插入失败返回提示
                return workOrder;
            }
        } catch (Exception e) {
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //遇到异常，返回异常原因
            e.printStackTrace();
            workOrder.setCode("1");
            workOrder.setMessage(e.getMessage());
            return workOrder;
        }
        finally {
            lock.unlock();
        }
    }
    /**
     *@Description:修改生产工单号表
     *@Param: [workOrder]
     *@return: int
     *@Author: zww
     *@date: 2020/11/16
     */
    @Override
    public WorkOrder updateWorkOrder(WorkOrder workOrder) {

        try {
            lock.lock();
            //生产工单号修改
            int rows = mainProductionMapper.updateWorkOrder(workOrder);
            //判断修改操作是否成功
            if (rows > 0) {
                workOrder.setCode("0");
                workOrder.setMessage("修改成功");
                //修改成功返回数据
                return workOrder;
            }
            else {
                workOrder.setCode("1");
                workOrder.setMessage("修改失败");
                //修改失败返回提示
                return workOrder;
            }
        } catch (Exception e) {
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //遇到异常，返回异常原因
            e.printStackTrace();
            workOrder.setCode("1");
            workOrder.setMessage(e.getMessage());
            return workOrder;
        }
        finally {
            lock.unlock();
        }
    }

}